<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字典数据维护</title>
    <script src="../../../resources/app/all.js" type="text/javascript"></script>
    <style type="text/css">
        a:link {
            text-decoration: none;
        }

        a:visited {
            text-decoration: none;
        }

        a:hover {
            text-decoration: none;
        }

        a:active {
            text-decoration: none;
        }

        #tag_ids2 a {
            padding: 2px 5px;
            background: #5FB878;
            border-radius: 2px;
            color: #fff;
            display: block;
            line-height: 20px;
            height: 24px;
            margin: 2px 5px 2px 0;
            float: left;
        }

    </style>
</head>
<body class="easyui-layout" data-options="fit:true">

<div data-options="region:'center'" style="padding: 5px;">
    <form class="layui-form layui-form-pane" action="" id="form" lay-filter="example">

        <div class="layui-form-item">
            <label class="layui-form-label">字典类型</label>
            <div class="layui-input-block">
                <input type="text" name="dictType" id="dictType" lay-verify="required" autocomplete="off"
                       placeholder="请输入字典类型"
                       class="layui-input ">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典标签</label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id">
                <input type="text" name="fieldLabel" lay-verify="required" autocomplete="off" placeholder="请输入字典标签"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典键值</label>
            <div class="layui-input-block">
                <input type="text" name="fieldVal" lay-verify="required" autocomplete="off"
                       placeholder="请输入字典键值"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="启用" checked="">
                <input type="radio" name="status" value="1" title="停用">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" name="orderAsc" lay-verify="required" autocomplete="off"
                       placeholder="请输入排序"
                       class="layui-input">
            </div>
        </div>
    </form>
</div>
<div data-options="region:'south',border:false">
    <div class="dialog-button">
        <button id="save" class="layui-btn layui-btn-normal">确定</button>
        <button id="cancel" class="layui-btn layui-btn-primary">取消</button>
    </div>
</div>

<script>
    layui.config({
        base: pathName + '/resources/module/'
    }).use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer;
        let parData = ToolUtil.OpenData();
        if (parData.act == 'edit') {
            let data = parData.data;
            form.val('example', JSON.parse(JSON.stringify(data)));
        } else {
            form.val('example', {
                dictType: parData.data
            });
        }
        layui.$("#dictType").addClass("layui-disabled");
        layui.$("#dictType").attr("disabled", true);

        layui.$('#save').on('click', function () {
            let data = ToolUtil.FormJSON("form");
            if (parData.act == 'edit') {
                ToolUtil.PUT({
                    url: global.api_url + '/sys/sysDictInfo',
                    data: JSON.stringify(data),
                    async: false,
                    success: function (obj) {
                        if (obj && obj.code === '00') {
                            saveClear()
                        } else if (obj.code === '98' || obj.code === '97') {
                            location.href = global.loginUrl;
                        } else {
                            layer.alert(obj.msg,{icon:5});
                        }
                    }
                });
            } else {
                ToolUtil.POST({
                    url: global.api_url + '/sys/sysDictInfo',
                    data: JSON.stringify(data),
                    async: false,
                    success: function (obj) {
                        if (obj && obj.code === '00') {
                            saveClear();
                        } else if (obj.code === '98' || obj.code === '97') {
                            location.href = global.loginUrl;
                        } else {
                            layer.alert(obj.msg,{icon:5});
                        }
                    }
                });
            }
        });
        layui.$('#cancel').on('click', function () {
            clear();
        });

        function saveClear() {
            parent.location.reload();
            clear();
        }

        function clear() {
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            layer.close(index);
        }


    });
</script>
</body>
</html>